package com.example.demo.java8.stream.stream_20200328;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @Author: liull
 * @Description: reduce/collect
 * @Date: Created in 13:44 2020/3/28
 * @Modified By:
 */
public class StreamApiTest3 {

    /**
     * reduce  计算1-10自然数的和
     */
    @Test
    public void test1() {
        //        int sum = IntStream.range(1, 11).sum();
        //        System.out.println(sum);
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        Integer reduce = list.stream().reduce(0, Integer::sum);
        System.out.println(reduce);
    }

    /**
     * collect
     */
    @Test
    public void test2() {
        
    }

}
